package com.chen.nio;

import java.nio.ByteBuffer;


/**
 * 通过 buf.asReadOnlyBuffer()创建只读buffer
 * 只读buffer只能用来读取数据，而不能用来写入数，
 * 如果往只读buffer里面写入数据会抛ReadOnlyBufferException
 */
public class NioTest6 {
    public static void main(String[] args) {
        ByteBuffer buf = ByteBuffer.allocate(100);
        String str = "hello world";
        buf.put(str.getBytes());
        ByteBuffer readBuf = buf.asReadOnlyBuffer();
        readBuf.put("a".getBytes());
    }
}
